#!/usr/bin/env python
#encoding=utf-8

import socket
import threading
import socketserver
import logging
from util.Logger import Logger

logger = logger = Logger('asynchronousSocketServer.log',logging.DEBUG,logging.DEBUG)
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):

    def setup(self):
        pass

    def handle(self):
        event = self.request.recv(2048)
        logger.debug(event)
        #处理event并写入数据库
        cur_thread = threading.current_thread()
        print(cur_thread)

    def finish(self):
        pass

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass



"""
if __name__ == "__main__":
    HOST, PORT = "10.22.8.22", 18003
    server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
    ip, port = server.server_address
    server_thread = threading.Thread(target=server.serve_forever)
    # Exit the server thread when the main thread terminates
    server_thread.daemon = True
    server_thread.start()
    print("Server loop running in thread:", server_thread.name)
"""